#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "public.h"


/*********************************************************************************************
** Function name:           gpio_conf
** Descriptions:            GPIO配置
** input parameters:        GPIOx：GPIO类型
                            Pins: GPIO引脚
                            Mode: GPIO模式
                            Speed: GPIO速度
** output parameters:       
** Returned value:          SMAG_SUCCESS: 成功
** Created by:              zheh.zhang
** Created date:            2021-09-03
**--------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**********************************************************************************************/
void gpio_conf(GPIO_TypeDef *GPIOx, uint16_t Pins, GPIOMode_TypeDef Mode, GPIOSpeed_TypeDef Speed) 
{
    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin = Pins;
    GPIO_InitStructure.GPIO_Speed = Speed;
    GPIO_InitStructure.GPIO_Mode = Mode;

    GPIO_Init(GPIOx, &GPIO_InitStructure); 
}


/*********************************************************************************************
** Function name:           nvic_conf
** Descriptions:            NVIC配置
** input parameters:        Channel：通道
                            Priority: 优先级
                            SubPriority: 次优先级
                            State: 使能状态
** output parameters:       none
** Returned value:          none
** Created by:              zheh.zhang
** Created date:            2021-09-03
**--------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**********************************************************************************************/
void nvic_conf(uint8_t Channel, uint8_t Priority, uint8_t SubPriority, FunctionalState State)
{
    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannel = Channel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = Priority;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = SubPriority;
    NVIC_InitStructure.NVIC_IRQChannelCmd = State;

    NVIC_Init(&NVIC_InitStructure);
}

/*********************************************************************************************
** Function name:           uart_conf
** Descriptions:            串口配置
** input parameters:        baud: 波特率
                            WordLength: 字长
                            StopBits: 停止位
                            Parity: 校验位
** output parameters:       none
** Returned value:          none
** Created by:              zheh.zhang
** Created date:            2021-09-03
**--------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**********************************************************************************************/
void uart_conf(USART_TypeDef *USARTx, uint32_t baud, uint16_t WordLength, uint16_t StopBits, uint16_t Parity)
{
    USART_InitTypeDef USART_InitStructure;

    //USART 初始化设置
	USART_InitStructure.USART_BaudRate = baud;						//串口波特率
	USART_InitStructure.USART_WordLength = WordLength;		//字长为8位数据格式
	USART_InitStructure.USART_StopBits = StopBits;			//一个停止位
	USART_InitStructure.USART_Parity = Parity;				//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式

	USART_Init(USARTx, &USART_InitStructure); 			//初始化串口1
	USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE);	//开启串口接受中断
	USART_Cmd(USARTx, ENABLE);                    	//使能串口1 
}



